<div class="page-header">
    <h1>
        Form Penarikan Poin
        <small>
            <i class="icon-double-angle-right"></i>
            Penarikan Saldo Poin
        </small>
    </h1>
</div>

<?php
if ($this->errmsg) {
    ?>
    <div class="alert alert-danger">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-remove"></i>
            Error <br>
        </strong>

        <?php echo $this->errmsg; ?>
        <br />
    </div>
    <?php
}

if ($this->msg) {
    ?>
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-ok"></i>            
        </strong>

        <?php echo $this->msg; ?>
        <br />
    </div>
    <?php
}

if (!$this->msg && !$this->errmsg) {
    ?>

    <div class="row">
        <div class="col-xs-11">
            <form id="formWD" class="form-horizontal" role="form" action="" method="post" onsubmit="return validate()">
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="acc_num"> Dari Nomor Akun </label>

                    <div class="col-sm-9">                        
                        <input readonly type="text" id="acc_num" name="acc_num" placeholder="Nomor Akun" value="<?php echo $this->acc_num; ?>" class="col-xs-10 col-sm-5" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="balance2">Saldo</label>
                    <div class="col-sm-9">
                        <input readonly type="text" id="balance2" name="balance2" placeholder="Saldo" value="<?php echo $this->amount2; ?>" class="col-xs-10 col-sm-5" />
                        <input type="hidden" name="balance" value="<?php echo $this->amount; ?>" id="balance">
                </div>

            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="tarik"> Jumlah Penarikan </label>

                <div class="col-sm-9">
                    <input type="text" id="tarik" name="tarik" placeholder="Cth: 1500000 (Tanpa titik/koma)" class="col-xs-10 col-sm-5" value="<?php if (isset( $this->tarik )) { echo $this->tarik;} ?>" required onkeypress='return validateNumber(event)' />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="min_saldo"> Minimum Saldo </label>

                <div class="col-sm-9">
                    <input type="text" id="min_saldo2" name="min_saldo2" class="col-xs-10 col-sm-5" value="<?php echo number_format($this->minbalance); ?>" readonly />
                    <input type="hidden" id="min_saldo" name="min_saldo" value="<?php echo $this->minbalance; ?>" />
                    <input type="hidden" id="min_withdraw" name="min_withdraw" value="<?php echo $this->minwithdraw; ?>" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="min_saldo"> Biaya </label>

                <div class="col-sm-9">
                    <input type="text" id="biaya2" name="biaya2" class="col-xs-10 col-sm-5" value="<?php echo number_format($this->biaya); ?>" readonly />
                    <input type="hidden" id="biaya" name="biaya" value="<?php echo $this->biaya; ?>" />

                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label no-padding-right" for="bank_name"> Transfer ke Bank </label>

                <div class="col-sm-9">
                    <input type="text" id="bank_name" name="bank_name" placeholder="Rekening Bank" class="col-xs-10 col-sm-5" value="<?php echo $this->bank; ?>" readonly />
                </div>
            </div>

            <div class="clearfix form-actions">
                <div class="col-md-offset-3 col-md-9">
                    <button class="btn btn-info" type="submit">
                        <i class="icon-ok bigger-110"></i>
                        Submit
                    </button>

                    &nbsp; &nbsp; &nbsp;
                    <button class="btn" type="reset">
                        <i class="icon-undo bigger-110"></i>
                        Reset
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>


<script>


    function validateNumber(evt) {

        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }

    function validate() {

        var msg = "";

        if ($('#acc_num').val() == "")
            msg = msg + "* Nomor Akun harus dipilih\n";

        if ($('#tarik').val() == "")
            msg = msg + "* Jumlah Penarikan harus diisi\n";

        if (eval($('#tarik').val()) < eval($('#min_withdraw').val()))
            msg = msg + "* Jumlah Penarikan minimal "+$('#min_withdraw').val()+"\n";

        if ((eval($('#balance').val()) - (eval($('#tarik').val()))) < eval($('#min_saldo').val()) || eval($('#balance').val()) < eval($('#min_saldo').val())){
            
            msg = msg + "* Minimum Saldo tidak mencukupi\n";
        }

        if ((eval($('#tarik').val()) + eval($('#biaya').val())) > eval($('#balance').val()))
            msg = msg + "* Jumlah Penarikan + Biaya lebih besar dari saldo\n";


        if (msg == "")
            return true;
        else {
            //alert("Data tidak lengkap:\n\n" + msg);
            //$.messager.alert("Data tidak lengkap:\n\n" + msg);
            alert(msg);
            return false;
        }
    }


</script>

<?php } ?>